package edu.whpu.sztz.utils;

import java.security.MessageDigest;

public class MD5Util {

	public static String getMD5(String string) throws Exception {
		MessageDigest messageDigest = MessageDigest.getInstance("MD5");
		messageDigest.reset();
		messageDigest.update(string.getBytes("UTF-8"));
		byte[] byteArray = messageDigest.digest();
		StringBuffer buffer = new StringBuffer();
		
		for (int i = 0; i < byteArray.length; i++) {              
			if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)  
                buffer.append("0").append(Integer.toHexString(0xFF & byteArray[i]));  
            else  
                buffer.append(Integer.toHexString(0xFF & byteArray[i]));  
        }  
		
		return buffer.toString();
	}
}
